package com.duqc.web.feign;

import lombok.Data;

/**
 * @ClassName Result
 * @Description Result
 * @Author duqc
 * @Date 2023/5/9
 **/
@Data
public class Result<T> {
    private int status;
    private String message;
    private T data;

    protected Result() {
    }

    public Result(StatusEnum statusEnum) {
        this.status = statusEnum.getCode();
        this.message = statusEnum.getMessage();
    }

    public Result(StatusEnum statusEnum, T data) {
        this.status = statusEnum.getCode();
        this.message = statusEnum.getMessage();
        this.data = data;
    }

    public Result(StatusEnum statusEnum, String message) {
        this.status = statusEnum.getCode();
        this.message = message;
    }

    public Result(StatusEnum statusEnum, T data, String message) {
        this.status = statusEnum.getCode();
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<>(StatusEnum.SUCCESS);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(StatusEnum.SUCCESS, data);
    }

    public static <T> Result<T> success(T data, String message) {
        return new Result<>(StatusEnum.SUCCESS, data, message);
    }

    public static <T> Result<T> error() {
        return new Result<>(StatusEnum.UNKNOWN);
    }

    public static <T> Result<T> fail(StatusEnum statusEnum) {
        return new Result<>(statusEnum);
    }

    public static <T> Result<T> fail(StatusEnum statusEnum, String message) {
        return new Result<>(statusEnum, message);
    }

    public static <T> Result<T> fail(StatusEnum statusEnum, T data) {
        return new Result<>(statusEnum, data);
    }

    public static <T> Result<T> fail(StatusEnum statusEnum, T data, String message) {
        return new Result<>(statusEnum, data, message);
    }
}
